import { netWork } from '@/network/request.js';

class Axios { // Axios请求构造类
  constructor () {
  }

  getRequst (url, params = null) { // GET请求函数
    return netWork({
      url,
      method: 'GET',
      params
    })
  }
  
  getPost (url, data = null) { // POST请求函数
    return netWork({
      url,
      method: 'POST',
      data
    })
  }

  getPut (url, params = null) { // POST请求函数
    return netWork({
      url,
      method: 'PUT',
      params
    })
  }

  getDel (url) {
    return netWork({
      url,
      method: 'DELETE'
    })
  }

}


function getAllRight (page) { // Home页面侧边栏请求
  return new Axios().getRequst('permission/findPermissionsByPage', page);
}

function postAddPermission(permission) {
  return new Axios().getPost('permission/addPermission', permission)
}

function delPermission(pid) {
  return new Axios().getDel(`permission/delPermission/${pid}`)
}

function getOnePermission(pid) {
  return new Axios().getRequst(`permission/findPermissionByPid`, {pid})
}

function postUpdPermission(permissionObj) {
  return new Axios().getPost(`permission/updatePermission`, permissionObj)
}

export {
  getAllRight,
  postAddPermission,
  delPermission,
  getOnePermission,
  postUpdPermission
}


